//
//  DrawViewController.m
//  leisure2
//
//  Created by xalo on 16/7/8.
//  Copyright © 2016年 蓝鸥科技有限公司西安分公司. All rights reserved.
//

#import "DrawViewController.h"

@interface DrawViewController ()<MenuViewControllerDelegate>
@property (nonatomic,strong)MenuViewController *menuVC;
@property (nonatomic,strong)UINavigationController *rightNVC;
@end

@implementation DrawViewController
//重写init方法
- (instancetype)initWithMenuViewController:(MenuViewController *)menuVC rightViewController:(RightViewController *)rightVC{
    self=[super init];
    if (self) {
        self.menuVC=menuVC;
        self.menuVC.delegate=self;
        self.rightNVC=[[UINavigationController alloc]initWithRootViewController:rightVC];
    }
    return self;
}
//点击cell的协议
- (void)menuViewControllerClickCellChangeVC:(RightViewController *)VC{
    //先把旧的向右偏移
    [UIView animateWithDuration:0.2 animations:^{
        self.rightNVC.view.frame=CGRectMake(kWidth, 0, kWidth, kHeight);
    } completion:^(BOOL finished) {
       //移除旧的控制器及其视图
        [self.rightNVC removeFromParentViewController];
        [self.rightNVC.view removeFromSuperview];
        //添加新的控制器及其视图
        self.rightNVC=[[UINavigationController alloc]initWithRootViewController:VC];
        [self addChildViewController:self.rightNVC];
        [self.view addSubview:self.rightNVC.view];
        //更改frame,是一直在右边
        self.rightNVC.view.frame=CGRectMake(kWidth, 0, kWidth, kHeight);
        //把新的控制器偏移回来
        [UIView animateWithDuration:0.2 delay:0.5 options:UIViewAnimationOptionLayoutSubviews animations:^{
            self.rightNVC.view.frame=self.view.frame;
        } completion:^(BOOL finished) {
            
        }];
        
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //添加控制器
    [self addChildViewController:self.menuVC];
    [self addChildViewController:self.rightNVC];
    //添加控制器视图
    [self.view addSubview:self.menuVC.view];
    [self.view addSubview:self.rightNVC.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
